/*==============================================
 * Task2b: Text, Fonts & Input
 *
 * Written by <YOUR NAME HERE>
 *
 *==============================================*/

#include <sstream>
#include "GameUtils.h"
#include "GameEngine.h"
#include "Fail.h"
#include "FontUtils.h"
#include "ConsoleOutput.h"


class CTask2b: public CGameEngine
{
	virtual bool Startup();
	virtual void Update(float dt);
	virtual void Draw(float dt);
	virtual void Shutdown();
protected:
	ID3DXFont* mpBigFont;
	ID3DXFont* mpLittleFont;
};

bool CTask2b::Startup()
{
	if (!StartupWinD3D(640,480,false))
		return false;

	mpBigFont=CreateD3DFont(mpDevice,"Comic Sans MS",48,true);
	mpLittleFont=CreateD3DFont(mpDevice);

	return true;
}
void CTask2b::Update(float dt)
{
	if (KeyPress(VK_F10))
		CloseWin();
}
void CTask2b::Draw(float dt)
{
    // Clear the backbuffer to a black color
    mpDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, BLACK_COL, 1.0f, 0 );
	mpDevice->BeginScene();

	// draw text:
	// title at top centre of screen
	// the DT_TOP|DT_CENTER|DT_NOCLIP prints the text centralised
	DrawD3DFontEx(mpBigFont,NULL,CGameWindow::VERSION,320,0,YELLOW_COL,DT_TOP|DT_CENTER|DT_NOCLIP);

	// make a string with info on the mouse:
	std::stringstream sout;
	sout<<"Mouse is at:";
	POINT p=GetMousePos();
	sout<<p.x<<" "<<p.y;
	sout<<"\nMouse move:";
	p=GetMouseDelta();
	sout<<p.x<<" "<<p.y<<" "<<GetMouseWheel();
	DrawD3DFont(mpLittleFont,sout.str(),0,400,CYAN_COL);

	mpDevice->EndScene();
    mpDevice->Present( NULL, NULL, NULL, NULL );
}

void CTask2b::Shutdown()
{
	SAFE_RELEASE(mpBigFont);
	SAFE_RELEASE(mpLittleFont);
	ShutdownD3D();
}


int WINAPI WinMain(HINSTANCE hInstance, 
				   HINSTANCE hPrevInstance, 
				   LPTSTR lpCmdLine, int nCmdShow)
{
	ENABLE_LEAK_DETECTION();
	CTask2b eng;
	return eng.Go(hInstance);	// runs everything
}
